package com.ItemsRent.Test;

import java.io.File;
import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ItemsRent.IService.ICustomer;
import com.ItemsRent.IService.IOrderForm;
import com.ItemsRent.action.CustomerAction;
import com.ItemsRent.action.ItemTableAction;
import com.ItemsRent.action.LoginAction;

import com.ItemsRent.action.OrderFormAction;
import com.ItemsRent.model.Customer;
import com.ItemsRent.model.OrderForm;


public class Test1 {
	@Autowired
	ApplicationContext ac = new ClassPathXmlApplicationContext(
			"applicationContext.xml");

	//@Test
	public void test1() {

		try {
			LoginAction loginAction = (LoginAction) ac.getBean("loginAction");
			loginAction.login();
			ICustomer cuService = (ICustomer) ac.getBean("customerService");
			Customer customer = cuService.getCustomer("201230740427", "123456");
			System.out.println("测试结果： " + customer.getNumber());
			System.out.println("***Test End!!!");
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}

	//@Test
	public void test2() {

		try {
			OrderFormAction orderFormAction = (OrderFormAction) ac.getBean("orderFormAction");
			orderFormAction.getCustomer().setCustomerId(1);
			//orderFormAction.showAllBook();
			IOrderForm orderFormService = (IOrderForm) ac.getBean("orderFormImpl");
			List<OrderForm> list/* itemTable*/ =orderFormService.findAllReceive(1);
			for(OrderForm order : list){
				System.out.println(order.getOrderId());
			}
			System.out.println("***Test End!!!");
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}
	
	@Test
	public void test3(){
		try {
			ItemTableAction itemTableAction = (ItemTableAction) ac.getBean("itemTableAction");
			//IitemTable itemTableService = (IitemTable) ac.getBean("itemTableImpl");
			//ItemType itemType=new ItemType("平板电脑","电子产品");
			
			
			//itemTableAction.setItemTypeName("平板电脑");
			//itemTableAction.FindItemTableByItemName();
			//itemTableAction.FindItemTableByItemName("平板电脑");
			
			//itemTableAction.FindByKeyword("电脑");
			
			/*
			//测试修改物品状态
			itemTableAction.setItemId(2);
			itemTableAction.setItemStatus(1);
			itemTableAction.SwitchItemStatus();
			*/
			
			
			//测试修改 物品信息
			itemTableAction.setItemId(2);
			itemTableAction.setItemName("肾六");
			itemTableAction.setItemDiscription("把妹必须");
			itemTableAction.setItemTypeName("手机");
			itemTableAction.setItemPicture("F:\\Pictures\\qq表情\\6.jpg");
			File file = new File("F:\\Pictures\\qq表情\\6.jpg");
			//System.out.println(file.toString());
			itemTableAction.setUpload(file);
			itemTableAction.setItemPrice(6000);
			itemTableAction.setItemNumber(2);
			itemTableAction.UpdateItemInfomation();
			
			/*
			//测试添加
			Customer customer = new Customer();//new Customer("201230740401", "e10adc3949ba59abbe56e057f20f883e", 1, "Mike", "123456", "111111", "SCAU", "616128085@qq.com", 1, "");
			customer.setCustomerId(1);
			//itemTableAction.setItemTypeId(7);
			itemTableAction.setItemTypeName("平板电脑");
			itemTableAction.setPtypeName("电子产品");
			itemTableAction.setCustomer(customer);
			itemTableAction.setItemName("平板");
			itemTableAction.setItemPrice(100);
			itemTableAction.setItemNumber(1);
			itemTableAction.setPicture("");
			itemTableAction.setItemDiscription("");
			itemTableAction.addItemTable();
			*/
			
			/*
			//测试更新
			itemTableAction.setItemId(13);
			itemTableAction.setItemTypeId(7);
			itemTableAction.setItemTypeName("平板电脑");
			itemTableAction.setPtypeName("电子产品");
			Customer customer = new Customer();
			customer.setCustomerId(1);
			itemTableAction.setCustomer(customer);
			itemTableAction.setItemName("ipad");
			itemTableAction.setItemPrice(100);
			itemTableAction.setItemNumber(1);
			itemTableAction.setPicture("");
			itemTableAction.setItemDiscription("");
			itemTableAction.updateItemTable();
			*/
			
			/*
			//测试删除
			itemTableAction.setItemId(13);
			itemTableAction.deleteItemTable();
			*/
			
			/*
			//测试返回所有上架物品
			itemTableAction.FindItemCanSee();
			*/
			
			System.out.println("***Test End!!!");
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}
	
	//@Test
	public void testCustomerAction(){
		CustomerAction cuAction = (CustomerAction) ac.getBean("customerAction");
		cuAction.setCuName("发哥");
		try{
		cuAction.cuEdit();
		}catch(Exception ex){
			ex.printStackTrace();
		}
		System.out.println("Test End!!!");
	}
	
	//@Test
	public void testOrderFormAction(){
		try{
			OrderFormAction o = (OrderFormAction) ac.getBean("orderFormAction");
			o.setItemId(9);
			o.saveOrder();
			System.out.println("Test End!!!");
		}catch(Exception ex){
			System.out.println(ex.getLocalizedMessage());
			ex.printStackTrace();
		}
	}
}
